package com.tz.controller;

import com.tz.entity.ZhangWu;
import com.tz.service.ZhangWuService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/addServlet")
public class AddServlet extends HttpServlet {
    private ZhangWuService zhangWuService = new ZhangWuService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.接收表单提交的数据，封装为一个Brand对象
        String flname = request.getParameter("flname");
        String money = request.getParameter("money");
        String zhanghu = request.getParameter("zhanghu");
        String createtime = request.getParameter("createtime");
        String description = request.getParameter("description");
        Double money1 = 0.0;
        System.out.println("==="+money);


        //2.封装为ZhangWu对象
        ZhangWu zhangWu = new ZhangWu();
        zhangWu.setFlname(flname);
//        zhangWu.setMoney(money1);
        zhangWu.setZhanghu(zhanghu);
        zhangWu.setCreatetime(createtime);
        zhangWu.setDescription(description);
//        zhangWu.setFlname(uid);

        //3.调用service层，完成添加
        zhangWuService.add(zhangWu);

        //3.转发到查询所有Servlet
//        request.getRequestDispatcher("/selestAllServlet").forward(request,response);
        String contextPath = request.getContextPath();
        response.sendRedirect(contextPath+"/selestAllServlet");



    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
